<template>
  <XtxDialog title="兑换我的礼品卡" v-model:visible="dialogVisible">
    <div class="card-content">
      <div class="form">
        <div class="form-item">
          <span class="label">礼品卡：</span>
          <input type="text" v-model="formData.exchangeCode" placeholder="请输入礼品卡密码">
        </div>
      </div>
    </div>
    <template v-slot:footer>
      <XtxButton @click="dialogVisible=false" type="gray" style="margin-right:20px">取消</XtxButton>
      <XtxButton @click="submit()" type="primary">确认</XtxButton>
    </template>
  </XtxDialog>
</template>

<script>
import { reactive, ref } from 'vue'
import Message from '@/components/library/message'
export default {
  name: 'GiftCardExchange',
  setup (props, { emit }) {
    const dialogVisible = ref(false)
    // 定义一个open函数，作为打开对话框函数(组件实例拥有open函数)
    const open = () => {
      dialogVisible.value = true
    }
    // 定义表单数据对象
    const formData = reactive({
      exchangeCode: null // 兑换码
    })
    // 添加完成后提交操作
    const submit = () => {
      if (formData.exchangeCode === null) {
        Message({ type: 'warn', text: '请输入兑换码' })
      } else {
        Message({ type: 'success', text: '礼品卡兑换成功' })
        // 关闭对话框
        dialogVisible.value = false
        formData.exchangeCode = ''
      }
    }
    return { dialogVisible, open, formData, submit }
  }
}
</script>

<style lang="less" scoped>
.xtx-dialog {
  :deep(.wrapper){
    // width: 940px;
    .body {
      font-size: 14px;
    }
  }
}
.card-content {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: space-around;
  // 右侧内容区
  .form {
    display: flex;
    flex-wrap: wrap;
    input {
      border: 1px solid #e4e4e4;
      padding-left: 10px;
    }
    .form-item {
      width: 100%;
      display: flex;
      line-height: 50px;
      justify-content: space-between;
      .label {
        // width: 100px;
        text-align: right;
        padding-right: 10px;
        color: #999;
      }
      input {
        width: 300px;
        height: 50px;
      }
    }
  }
}
</style>
